/*
 * Copyright 2006 Matt Jensen
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package org.spectaql.internal.metadata;

import org.spectaql.metadata.PropertyMetadata;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.lang.reflect.Method;

/**
 * <p>
 * <code>PropertyMetadataImpl</code> is the default implementation of the {@link PropertyMetadata} interface.
 * </p>
 */
class PropertyMetadataImpl implements PropertyMetadata
{
    private static Log LOG = LogFactory.getLog(PropertyMetadataImpl.class);
    
    /**
     * <p>
     * The property name.
     * </p>
     */
    private final String m_name;

    /**
     * <p>
     * Flag indicating whether the property is the instance identifier property. 
     * </p>
     */
    private final boolean m_identifierProperty;

    /**
     * <p>
     * Flag indicating whether the property is nullable.
     * </p>
     */
    private final boolean m_nullable;

    /**
     * <p>
     * The class of the property.
     * </p>
     */
    private final Class<?> m_propertyClass;

    /**
     * <p>
     * The property accessor method. 
     * </p>
     */
    private final Method m_readMethod;

    /**
     * <p>
     * The property mutator method. 
     * </p>
     */
    private final Method m_writeMethod;

    /**
     * <p>
     * Construct a {@link PropertyMetadata} instance.
     * </p>
     *
     * @param name the property name.
     * @param propertyClass the property class.
     * @param nullable flag indicating whether the property is nullable.
     * @param readMethod the property accessor method.
     * @param writeMethod the property mutator method.
     * @param identifierProperty the identifier property flag.
     */
    public PropertyMetadataImpl(final String name,
                                final Class<?> propertyClass,
                                final boolean nullable, 
                                final Method readMethod,
                                final Method writeMethod,
                                final boolean identifierProperty)
    {
        super();
        assert null != name : "The [name] argument cannot be null.";
        assert null != propertyClass : "The [propertyClass] argument cannot be null.";
        assert null != readMethod : "The [readMethod] argument cannot be null.";

        m_identifierProperty = identifierProperty;
        m_name = name;
        m_nullable = nullable;
        m_propertyClass = propertyClass;
        m_readMethod = readMethod;
        m_writeMethod = writeMethod;
    }


    /* inherit javadoc */
    public String getName()
    {
        return m_name;
    }

    /* inherit javadoc */
    public boolean isIdentifierProperty()
    {
        return m_identifierProperty;
    }

    /* inherit javadoc */
    public boolean isNullable()
    {
        return m_nullable;
    }

    /* inherit javadoc */
    public Class<?> getPropertyClass()
    {
        return m_propertyClass;
    }


    /* inherit javadoc */
    public Method getReadMethod()
    {
        return m_readMethod;
    }

    /* inherit javadoc */
    public Method getWriteMethod()
    {
        return m_writeMethod;
    }
}
